/*
 *  kitButton.cpp
 *  xboxControllers
 *
 *  Created by Arne Boon on 4/3/10.
 *  Copyright 2010 __MyCompanyName__. All rights reserved.
 *
 */

#include "kitButton.h"
#include <iostream>

//--------------------------------------------
kitButton::kitButton()	
{
	isActive = false;
	pos.x = ofGetWidth()/2;
	pos.y = ofGetHeight()/2;
	cActive = 255;
	cPassive = 170;
}

//--------------------------------------------
kitButton::~kitButton() {
	delete this->counter;
	printf("*** kitButton Destroyed ***\n");
}

//--------------------------------------------
void kitButton::setup()
{
	//default setup
	color.r = 255;
	color.g = 255;
	color.b = 255;
	circleSize = 50;
	circleRes = 360;
}

//--------------------------------------------
void kitButton::setup(uint r, uint g, uint b, uint size, uint res, uint x, uint y)
{
	color.r = r;
	color.g = g;
	color.b = b;
	circleSize = size;
	circleRes = res;
	pos.x = x;
	pos.y = y;
	
	this->counter = new TimedCounter(0,COUNTER_END,1);
}

//--------------------------------------------
void kitButton::update()
{
	if(this->counter->isCounting()){
		this->counter->update();
		if(this->counter->hasChanged()) {
			//cout << "counter changed:" << this->counter->getCurrentCount() << endl;
		}
		if(this->counter->isCountComplete()) {
			this->counter->endCount();
			isActive = false;
			//cout << "counter complete!" << endl;
		}
	}
}

//--------------------------------------------
void kitButton::draw() 
{
	if(isActive) {
		ofSetColor(color.r, color.g, color.b, cActive);
	} else {
		ofSetColor(color.r, color.g, color.b, cPassive);
	}
	
	ofSetCircleResolution(circleRes);
	ofCircle(pos.x, pos.y, circleSize);
}

//--------------------------------------------
void kitButton::setColor(uint r, uint g, uint b)
{
	color.r = r;
	color.g = g;
	color.b = b;
}

//-------------------------------------------
void kitButton::setCircle(uint size, uint res) 
{
	circleSize = size;
	circleRes = res;
}

//-------------------------------------------
void kitButton::setPosition(uint x, uint y) 
{
	pos.x = x;
	pos.y = y;
}

//--------------------------------------------
void kitButton::toggleActive() 
{
	isActive = true;
	this->counter->startCount();
}






